const puppeteer = require('puppeteer');

let browser
let page
let isDebugging = false
beforeAll(async () => { 
  browser = await puppeteer.launch({
    headless: false,
  }) 
  isDebugging = true
  page = await browser.newPage() 
  await page.goto('http://localhost:8080/buy.html') 
})

afterAll( () => {
  if (isDebugging) {
    browser.close()
  }
})

describe ('is buy page Start rightly', () => {
  test('is video show Rightly', async () => {
    const video
    await page.waitForSelector('#buyVideo')
    video = page.$$('#buyVideo')
    await page.waitForSelector('.play-icon')
    await page.click('.play-icon')
    await page.waitFor(1000)
    video.pause()
  })
  test ('is modal show Rigntly', async () => {
    await page.waitForSelector('.buyArea')
    await page.click('.buyArea')
    const modal = await page.$eval('.model-main', el => el ? true : false)

    expect(modal).toBeTruthy()
  })
  test ('is submit could work' , async () => {
    await page.waitForSelector('.model-main input', 1000)
    //page.type('.model-main input', '', {delay: 100})
    await page.waitForSelector('.model-main button', 1000)
    await page.click('.model-main button')
    const errorMsg = await page.$eval('.model-main .error-tips', el => el.innerHTML? true : false)

    expect(errorMsg).toBeFalsy()
  })
})
